import java.io.IOException;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class Panel01 extends JPanel {
	private DefaultTableModel tableBase;
	private JTable table;
	private String path = "/home/jripolles/prueba/";
	private Diario miDiario;


	/**
	 * Create the panel.
	 */
	public Panel01() {
		tableBase = new DefaultTableModel(
				new Object[][] {
				},
				new String[] {
					"Apunte", "Fecha", "Descripci\u00F3n", "Importe"
				}
			) {
				Class[] columnTypes = new Class[] {
					Integer.class, String.class, String.class, Double.class
				};
				public Class getColumnClass(int columnIndex) {
					return columnTypes[columnIndex];
				}
			};
		table = new JTable(tableBase);
		JScrollPane scroll=new JScrollPane(table);
		scroll.setBounds(12,345,567,165);
		add(scroll);
		try {
			miDiario = new Diario(path+"diario01");
		} catch (IOException e1) {
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		}
		for (int aux = 0; aux < miDiario.getTamanyo(); aux++){
			Apunte ap = miDiario.getApunte(aux);
			Object [] fila ={ap.getNum_apunte(), ap.getFecha(), ap.getDescripcion(), ap.getImporte()};
			tableBase.addRow(fila);
		}


	}
	
	public void Cerrar(){
		try {
			miDiario.Guardar(path+"diario01");
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

}
